<?php
namespace app\yunda\admin;

use app\common\builder\ZBuilder;
use app\yunda\model\Yjrecord;
use think\Db;

/**
 * Class Category用户佣金记录
 * @package app\yunda\admin
 */
class Yj extends Base{
    public function index()
    {
        // 获取查询和排序规则
        $map = $this->getMap();
        $order = $this->getOrder();
        $map['r.delete_time']=NULL;
        $data = Db::view('dp_yj_record r',true)
             ->view('yd_user gu',['nickname'=>'getname'],'gu.openid=r.openid')
             ->view('yd_user pu',['nickname'=>'payname'],'pu.openid=r.pay_user_openid')
            ->where($map)
            ->order($order)
            ->order('r.id desc')
            ->paginate()->each(function($item){

                $item['level']=config('yongjin_type')[$item['level']];
                return $item;
            });
//        halt($data);
        return ZBuilder::make('table')
            ->setTableName('yj_record')  //需要修改 这里修改正确可以直接修改字段 删除
            ->addColumns([
                ['id','id'],
                ['getname','用户'],
                ['get_money','获取佣金'],
                ['payname','消费用户'],
                ['pay_money','消费金额'],
                ['level','佣金级别'],
                ['create_time','创建时间','datetime'],
            ])
            ->setRowList($data)
            ->addFilter(['getname'=>'yd_user gu.nickname', 'payname'=>'yd_user pu.nickname'])
            ->setSearch(['id' => 'ID'])
            ->addTimeFilter('r.create_time') // 添加时间段筛选
            ->fetch();
    }

}